var net = require('net');
var server = net.createServer(function(c) { //'connection' listener
  console.log('server connected\n');
  c.write('hello\r');
  c.pipe(c);
  c.on('data', function(data) {
	console.log('client: '+data);
  });
//  c.on('end', function() {
//	console.log('server disconnected\n');
//  });
});
//server.on('error', function (e) {
//	  if (e.code == 'EADDRINUSE') {
//	    console.log('Address in use, retrying...');
//	    setTimeout(function () {
//	      server.close();
//	      server.listen(PORT, HOST);
//	    }, 1000);
//	  }
//});

server.listen(8124, function() { //'listening' listener
  console.log('server bound');
  console.log('---'+server.address());
});